﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using YawetagDemo.Framework.Data;

namespace YawetagDemo.Framework.Server.Data
{
    [DataContract(IsReference = true)]
    public class WCFAlbum : IAlbum
    {
        private WCFAlbum(IAlbum album, IDictionary<object, object> references)
        {
            references.Add(album, this);

            AlbumID = album.AlbumID;

            BandID = album.BandID;
            Band = WCFBand.Get(album.Band, references);
            
            Name = album.Name;
            ReleaseDate = album.ReleaseDate;
        }

        public static WCFAlbum Get(IAlbum album, IDictionary<object, object> references)
        {
            return (WCFAlbum)(references.ContainsKey(album) ? references[album] : new WCFAlbum(album, references));
        }

        [DataMember] public int AlbumID { get; private set; }

        [DataMember] public int BandID { get; private set; }

        [DataMember] public WCFBand Band { get; private set; }
        IBand IAlbum.Band { get { return Band; } }

        [DataMember] public string Name { get; private set; }
        [DataMember] public DateTime ReleaseDate { get; private set; }
    }
}
